#import irc
import irc_protocol


bakeneko_version = u"Bakeneko (\u5316\u3051\u732b) bot 0.1a".encode("utf-8")


########################################
##
## Attaches itself to plugin list
##
def link( commands, help ):
    help["help"]= ['gives help on commands',
                      ['try !help and !help <command>' ]
                   ]
    commands["help"]=process_command


    
########################################
##
## parses the !help special command.
##
## if no parameters, shows a list of
## possible help topics (not necessarily
## commands)
##
## if a parameter is given, help for that
## specific command is given
##
##
def process_command( server, command, help, authenticate ):

    command_line = command[3].split(' ')
    if len(command_line)==1:
        # show top-level help
        server.send(
            irc_protocol.reply_private( command,
                "Help on the following commands is available:" ))
        server.send(
            irc_protocol.reply_private( command,
                "--------------------------------------------" ))
        
        for help_topic in help:
            server.send(
                irc_protocol.reply_private( command,help_topic.ljust(20)+
                                            help[help_topic][0]))

        server.send(
            irc_protocol.reply_private( command,
                "--------------------------------------------" ))
        server.send(
            irc_protocol.reply_private( command,
                "use !help <command> to get more help on <command>"))
        
    elif len(command_line)==2:
        help_topic=command_line[1]
        if help.has_key(help_topic):
            server.send(
                irc_protocol.reply_private(command,"Help on "+help_topic))
            for help_line in help[help_topic][1]:
                server.send(irc_protocol.reply_private( command, help_line))
        else:
            server.send(
                irc_protocol.reply_private(
                    command,"no such topic, try !help"))
    else:
        server.send(
            irc_protocol.reply_private(
                command, "too many parameters. Try help."))


